package com.adacms.data.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.adacms.data.core.Finder;
import com.adacms.data.core.Pagination;
import com.adacms.data.core.Updater;
import com.adacms.data.dao.DaysUserDao;
import com.adacms.data.entity.DaysUser;
import com.adacms.data.service.DaysUserService;

@Service
@Transactional
public class DaysUserServiceImpl implements DaysUserService {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}

	@Transactional(readOnly = true)
	public DaysUser findById(Integer id) {
		DaysUser entity = dao.findById(id);
		return entity;
	}

	@Transactional
	public DaysUser save(DaysUser bean) {
		dao.save(bean);
		return bean;
	}

	@Transactional
	public DaysUser update(DaysUser bean) {
		Updater<DaysUser> updater = new Updater<DaysUser>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

	@Transactional
	public DaysUser deleteById(Integer id) {
		DaysUser bean = dao.deleteById(id);
		return bean;
	}

	@Transactional
	public DaysUser[] deleteByIds(Integer[] ids) {
		DaysUser[] beans = new DaysUser[ids.length];
		for (int i = 0, len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private DaysUserDao dao;

	@Autowired
	public void setDao(DaysUserDao dao) {
		this.dao = dao;
	}

	@Transactional(readOnly = true)
	@Override
	public DaysUser login(String phonenum, String password) {
		DaysUser result = null;
		Finder finder = Finder.create();
		finder.append("from DaysUser u where u.phonenum ='" + phonenum + "'");
		finder.append(" and  u.password ='" + password + "'");
		List<DaysUser> users = dao.find(finder);
		if(users!=null&&users.size()>0){
			result=users.get(0);
		}
		return result;
	}
	@Transactional(readOnly = true)
	@Override
	public DaysUser checkphone(String phonenum) {
		DaysUser result = null;
		Finder finder = Finder.create();
		finder.append("from DaysUser u where u.phonenum ='" + phonenum + "'");
		List<DaysUser> users = dao.find(finder);
		if(users!=null&&users.size()>0){
			result=users.get(0);
		}
		return result;
	}
}